<script>
  // 练习1：有已知已下购物车数据，每一个都选中了，则返回的全选状态为true（选中了），只要有一个没有选中则返回false(未选中了)

  let cartGoods = [
    {
      goodsname: "小米10",
      price: 5000,
      isChecked: true, //代表是否选中了
    },
    {
      goodsname: "苹果10",
      price: 3000,
      isChecked: false, //代表是否选中了
    },
  ];
  function getCartComputed(arr) {
    let state=true;
    for (let i = 0; i < arr.length; i++) {
      if (!arr[i].isChecked) {
        state=false;
        break;
      }
    }
    return state;
  }
  console.log(getCartComputed(cartGoods)); //false

  // 练习2：有已知以下某公司员工薪金信息，把每一位员工的salary薪金信息 加 2000，并返回新数组，注意：不影响原数组
  let persons = [
    {
      username: "张飞",
      sex: "男",
      salary: 50000,
    },
    {
      username: "关羽",
      sex: "男",
      salary: 60000,
    },
  ];
  let persons1 = JSON.stringify(persons);
  let persons2 = JSON.parse(persons1);
  function getPerSalary(arr) {
    let arr1 = [];
    for (let attr in arr) {
      arr[attr].salary += 2000;
      arr1.push(arr[attr]);
    }
    return arr1;
  }
  console.log(getPerSalary(persons2));

  //练习3
  let str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  let cites = [
    { py: "beijing", name: "北京" },
    { py: "alishan", name: "阿里山" },
    { py: "beidaihe", name: "北戴河" },
    { py: "shijiazhuang", name: "石家庄" },
  ];
  let arr = {};
  for (let i=0;i<str.length;i++) {
      arr[str[i]] = [];
    for (var j = 0; j < cites.length; j++) {
      if (cites[j].py.toUpperCase().startsWith(str[i])) {
        arr[str[i]].push(cites[j]);
      }
    }
  }
  console.log(arr);
  
</script>
